package com.demo.listener;

import com.demo.bean.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author WuLiangHang
 */
@WebServlet(name = "Demo02Servlet", urlPatterns = "/demo02.do")
public class Demo02Servlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Student> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            list.add(new Student(i, "name" + i, i + 10, "phone" + i));
        }
        request.setAttribute("studentList", list);
        //请求转发 把皮球踢给目标JSP
        request.getRequestDispatcher("/WEB-INF/demo05.jsp").forward(request, response);
    }
}
